package com.ruoyi.quartz.task;

import java.util.List;

import org.springframework.stereotype.Component;

import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.utils.http.HttpUtils;
import com.ruoyi.quartz.service.ISysJobLogService;
import com.ruoyi.quartz.util.SpringContextUtil;
import com.ruoyi.quartz.util.SpringTaskContextUtil;
import com.ruoyi.user.domain.Machine;
import com.ruoyi.user.service.IMachineService;

/**
 * 定时任务调度测试
 * 
 * @author ruoyi
 */
@Component("ryTask")
public class RyTask
{
    public void ryParams(String params)
    {
        System.out.println("执行有参方法：" + params);
    }

    public void ryNoParams()
    {
        System.out.println("执行无参方法");
    }
    
    public void runLocation()
    {
    	IMachineService machineService = (IMachineService) SpringContextUtil.getBean("machineServiceImpl");
    	/*IMachineService machineService = (IMachineService)SpringTaskContextUtil.getBean(IMachineService.class);*/
    	List<Machine> list = machineService.selectMachineList(null);	
    	for(Machine machine:list){
    		/*System.out.println("执行获取定位请求方法");*/
            JSONObject param = new JSONObject();
    		param.put("imei", machine.getCode());
    		/*System.out.println(param.toJSONString());*/
    		String response = HttpUtils.sendPutJson("http://api.jiai.pro:8080/jiai/location", param.toJSONString(),machine.getCode());
    		/*System.out.println(response);*/
    		JSONObject res = (JSONObject) JSONObject.parse(response);
    		String errc = (String) res.get("code");
    		if("0000".equals(errc)){
    			/*System.out.println("执行获取定位请求方法成功！！！");*/
    		}else{
    			String message = (String) res.get("message");
    			/*System.out.println("执行获取定位请求方法失败："+message);*/
    		}
    	}
    }
    
    public void runHealth()
    {
    	IMachineService machineService = (IMachineService) SpringContextUtil.getBean("machineServiceImpl");
    	/*IMachineService machineService = (IMachineService)SpringTaskContextUtil.getBean(IMachineService.class);*/
    	List<Machine> list = machineService.selectMachineList(null);	
    	for(Machine machine:list){
    		try {
    			JSONObject param = new JSONObject();
    			param.put("imei", machine.getCode());
    			String response = HttpUtils.sendPutJson("http://api.jiai.pro:8080/jiai/heartRates", param.toJSONString(),machine.getCode());
    			JSONObject res = (JSONObject) JSONObject.parse(response);
    			String errc = (String) res.get("code");
    			if("0000".equals(errc)){
    			}else{
    				String message = (String) res.get("message");
    				System.out.println(message);
    			}
    			String response1 = HttpUtils.sendPutJson("http://api.jiai.pro:8080/jiai/bloodPressure", param.toJSONString(),machine.getCode());
				JSONObject res1 = (JSONObject) JSONObject.parse(response1);
				String errc1 = (String) res1.get("code");
				if("0000".equals(errc1)){
				}else{
					String message1 = (String) res1.get("message");
					System.out.println(message1);
				}
    		} catch (Exception e) {
    			e.printStackTrace();
    		}
    	}
    }
}
